using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using RAG.Application.Services;
using RAG.Application.Interfaces;
using RAG.Domain.Interfaces;
using RAG.Domain.EventHandlers;

namespace RAG.Application;

public static class ServicesCollectionExtensition
{
    public static IServiceCollection AddApplication(this IServiceCollection services, IConfiguration configuration)
    {
        // 注册应用服务
        services.AddScoped<IAppAuthService, AppAuthServices>();
        services.AddScoped<IAppLogService, LogService>();
        services.AddScoped<IAppTokenService, AppTokenService>();
        services.AddScoped<IAppUserService, AppUserService>();
        services.AddScoped<IAppRoleService, AppRoleService>();
        services.AddScoped<IAppPermissionService, AppPermissionService>();
        services.AddScoped<IAppAvatarService, AppAvatarService>();
        
        // 注册权限检查服务
        services.AddScoped<PermissionCheckService>();
        
        // 注册RAG相关服务
        services.AddScoped<IAppDocumentService, AppDocumentService>();
        services.AddScoped<IAppKnowledgeBaseService, AppKnowledgeBaseService>();
        services.AddScoped<IAppRagService, AppRagService>();
        services.AddScoped<IAppQAManagementService, AppQAManagementService>();
        services.AddScoped<IAppVectorService, AppVectorService>();
        services.AddScoped<IDocumentProcessingService, DocumentProcessingService>();
        services.AddScoped<IVectorService, VectorService>();
        services.AddScoped<IAppSystemService, AppSystemService>();

        // 注册领域事件发布器
        services.AddScoped<IDomainEventPublisher, DomainEventPublisher>();

        // 注册领域事件处理器（使用Application层的处理器）
        services.AddScoped<IDomainEventHandler<RAG.Domain.DomainEvents.UserRegisteredEvent>, RAG.Application.Services.UserRegisteredEventHandler>();
        services.AddScoped<IDomainEventHandler<RAG.Domain.DomainEvents.UserLoggedInEvent>, RAG.Application.Services.UserLoggedInEventHandler>();
        services.AddScoped<IDomainEventHandler<RAG.Domain.DomainEvents.UserLoginFailedEvent>, RAG.Application.Services.UserLoginFailedEventHandler>();
        services.AddScoped<IDomainEventHandler<RAG.Domain.DomainEvents.UserCreatedEvent>, RAG.Application.Services.UserCreatedEventHandler>();

        return services;
    }
}